package org.zerg.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.zerg.dao.ManageDao;
import org.zerg.dto.Page;
import org.zerg.entity.Manage;
import org.zerg.service.ManageService;

@Service
public class ManageServiceImpl implements ManageService{
	
	@Autowired
	private ManageDao manageDao;

	public Manage checkManage(String admin, String password) {
		List<Manage> list = manageDao.checkManage(admin, password);
		if(list.size()==1){
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<Manage> getManage(int page) {
		int total = manageDao.getManageTotal();
		if((page-1)*15>total){
			return null;
		}
		List<Manage> list = manageDao.getManageAllPage((page-1)*15);
		return list;
	}

	@Override
	public Page pageMessage(int page) {
		int total = manageDao.getManageTotal();
		double to = total;
		int totalPage = (int) Math.ceil(to/15);
		Page pa = new Page(page,totalPage,total,15);
		return pa;
	}

	@Override
	public void inserManage(Manage manage) {
		manageDao.inserManage(manage);
	}

	@Override
	public void updateManage(Manage manage) {
		manageDao.updateManage(manage);
	}

	@Override
	public void deleteManage(int id) {
		manageDao.deleteManage(id);
	}

	@Override
	public boolean isName(String name) {
		boolean result = true;
		Manage manage = manageDao.isName(name);
		if(manage == null){
			result = false;
		}
		return result;
	}

	@Override
	public boolean isAdmin(String admin) {
		boolean result = true;
		Manage manage = manageDao.isAdmin(admin);
		if(manage == null){
			result = false;
		}
		return result;
	}


}
